//Design By Do Trung --- Email : trungqn19852003@yahoo.com
//Ngày Design :5/4/2011 5:00:13 PM
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using System.Collections.Generic;
 
	/// <summary>
	/// </summary>
	public class Menu_DA
	{
		public Menu_DA() {}
#region 'Variables And Properties'
		 private int int_IdMenu ;
		 public int IdMenu
			{
			 get 	
				{
					 return this.int_IdMenu;
				}
			 set 	
				{
					int_IdMenu=value;
				}
			}
		 private int int_IdMenuSub ;
		 public int IdMenuSub
			{
			 get 	
				{
					 return this.int_IdMenuSub;
				}
			 set 	
				{
					int_IdMenuSub=value;
				}
			}
		 private string string_TenMenu ;
		 public string TenMenu
			{
			 get 	
				{
					 return this.string_TenMenu;
				}
			 set 	
				{
					string_TenMenu=value;
				}
			}
		 private int int_SapXep ;
		 public int SapXep
			{
			 get 	
				{
					 return this.int_SapXep;
				}
			 set 	
				{
					int_SapXep=value;
				}
			}
		 private bool bool_HienThi_TinTuc ;
		 public bool HienThi_TinTuc
			{
			 get 	
				{
					 return this.bool_HienThi_TinTuc;
				}
			 set 	
				{
					bool_HienThi_TinTuc=value;
				}
			}
		 private bool bool_HienThi_MenuChinh ;
		 public bool HienThi_MenuChinh
			{
			 get 	
				{
					 return this.bool_HienThi_MenuChinh;
				}
			 set 	
				{
					bool_HienThi_MenuChinh=value;
				}
			}
		 private bool bool_HienThi_MenuBottom ;
		 public bool HienThi_MenuBottom
			{
			 get 	
				{
					 return this.bool_HienThi_MenuBottom;
				}
			 set 	
				{
					bool_HienThi_MenuBottom=value;
				}
			}
#endregion

		/// <summary>
		/// Inserts a record into the Menu table.
		/// <summary>
		/// <param name="IdMenu"></param>
		/// <param name="IdMenuSub"></param>
		/// <param name="TenMenu"></param>
		/// <param name="SapXep"></param>
		/// <param name="HienThi_TinTuc"></param>
		/// <param name="HienThi_MenuChinh"></param>
		/// <param name="HienThi_MenuBottom"></param>
		/// <returns></returns>
		public bool Insert(SqlConnection SqlCnn)
		{
			bool boolInsert = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_Menu_Insert";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;
			SqlCmd.Parameters.Add("@IdMenuSub", SqlDbType.Int).Value=IdMenuSub;
			SqlCmd.Parameters.Add("@TenMenu", SqlDbType.NVarChar,50).Value=TenMenu;
			SqlCmd.Parameters.Add("@SapXep", SqlDbType.Int).Value=SapXep;
			SqlCmd.Parameters.Add("@HienThi_TinTuc", SqlDbType.Bit).Value=HienThi_TinTuc;
            SqlCmd.Parameters.Add("@HienThi_MenuChinh", SqlDbType.Bit).Value = HienThi_MenuChinh;
            SqlCmd.Parameters.Add("@HienThi_MenuBottom", SqlDbType.Bit).Value = HienThi_MenuBottom;

			SqlAdp.InsertCommand = SqlCmd;
			SqlAdp.InsertCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolInsert = true;
			}
			catch
			{
			boolInsert = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolInsert;
		}

		/// <summary>
		/// Selects a single record from the Menu table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable Select(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_Menu_Select";
			SqlCmd.CommandType=CommandType.StoredProcedure;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
		}

		/// <summary>
		/// Selects a single record from the Menu table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable SelectPrimaryKey(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_Menu_SelectPrimaryKey";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
			}

		/// <summary>
		/// Updates a record in the Menu table.
		/// <summary>
		/// <param name="IdMenu"></param>
		/// <param name="IdMenuSub"></param>
		/// <param name="TenMenu"></param>
		/// <param name="SapXep"></param>
		/// <param name="HienThi_TinTuc"></param>
		/// <param name="HienThi_MenuChinh"></param>
		/// <param name="HienThi_MenuBottom"></param>
		public bool Update(SqlConnection SqlCnn)
		{
			bool boolUpdate = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_Menu_Update";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;
			SqlCmd.Parameters.Add("@IdMenuSub", SqlDbType.Int).Value=IdMenuSub;
			SqlCmd.Parameters.Add("@TenMenu", SqlDbType.NVarChar,50).Value=TenMenu;
			SqlCmd.Parameters.Add("@SapXep", SqlDbType.Int).Value=SapXep;
            SqlCmd.Parameters.Add("@HienThi_TinTuc", SqlDbType.Bit).Value = HienThi_TinTuc;
            SqlCmd.Parameters.Add("@HienThi_MenuChinh", SqlDbType.Bit).Value = HienThi_MenuChinh;
            SqlCmd.Parameters.Add("@HienThi_MenuBottom", SqlDbType.Bit).Value = HienThi_MenuBottom;

			SqlAdp.UpdateCommand = SqlCmd;
			SqlAdp.UpdateCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolUpdate = true ;
			}
			catch
			{
			boolUpdate = false ;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolUpdate;
		}

		/// <summary>
		/// Deletes a record from the Menu table by a composite primary key.
		/// <summary>
		public bool Delete(SqlConnection SqlCnn)
		{
			bool boolDelete = false;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_Menu_Delete";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;

			SqlAdp.DeleteCommand = SqlCmd;
			SqlAdp.DeleteCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolDelete = true;
			}
			catch
			{
                boolDelete = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolDelete;
			}
	}

